﻿using System;
/*
 * Write an expression that extracts from a given integer i the value of a given bit number b.
 * Example: i=5; b=2  value=1.
 */

class TheValueOfABitAtPositionP
{
    static void Main(string[] args)
    {
        int parameter = 5;
        int position = 2;
        string parameterBinary = Convert.ToString(parameter, 2).PadLeft(32, '0');
        int mask = 1 << position;
        int maskAndParameter = parameter & mask;
        int result = maskAndParameter >> position;
        Console.WriteLine("The value of the bit at position {2} in the binary representation of {0}:\n{1}\nis {3}",parameter,parameterBinary, position, result);
    }
}
